const Pick = require("../template")

function testPickAdvancedMethods() {
  console.log(
    "1. 对象选择高级方法 - 深度路径选择测试:",
    (() => {
      const object = { user: { name: 'John', age: 30 }, data: { value: 100 } }
      const result = Pick.pickDeep(object, 'user.name', 'data.value')
      const expected = { user: { name: 'John' }, data: { value: 100 } }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "2. 对象选择高级方法 - 条件选择测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4 }
      const result = Pick.pickBy(object, (value) => value % 2 === 0)
      const expected = { b: 2, d: 4 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "3. 对象选择高级方法 - 类型选择测试:",
    (() => {
      const object = { a: 1, b: 'hello', c: 3, d: 'world' }
      const result = Pick.pickByType(object, 'string')
      const expected = { b: 'hello', d: 'world' }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "4. 对象选择高级方法 - 正则选择测试:",
    (() => {
      const object = { user_name: 'John', user_age: 30, data_value: 100 }
      const result = Pick.pickByPattern(object, /^user_/)
      const expected = { user_name: 'John', user_age: 30 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "5. 对象选择高级方法 - 默认值选择测试:",
    (() => {
      const object = { a: 1, b: 2 }
      const result = Pick.pickWithDefaults(object, 'a', 'c', { c: 0 })
      const expected = { a: 1, c: 0 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "6. 对象选择高级方法 - 转换选择测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3 }
      const result = Pick.pickWithTransform(object, 'a', 'b', { a: (val) => val * 2 })
      const expected = { a: 2, b: 2 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "7. 对象选择高级方法 - 验证选择测试:",
    (() => {
      const object = { name: 'John', age: 30, email: 'john@example.com' }
      const result = Pick.pickWithValidation(object, 'name', 'age', {
        name: 'string',
        age: 'number'
      })
      const expected = { name: 'John', age: 30 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "8. 对象选择高级方法 - 空对象选择测试:",
    (() => {
      const object = {}
      const result = Pick.pick(object, 'a', 'b')
      return Object.keys(result).length === 0
    })()
  )

  console.log(
    "9. 对象选择高级方法 - 单属性对象选择测试:",
    (() => {
      const object = { a: 1 }
      const result = Pick.pick(object, 'a')
      return result.a === 1
    })()
  )

  console.log(
    "10. 对象选择高级方法 - 复杂对象选择测试:",
    (() => {
      const object = {
        user: { name: 'John', age: 30 },
        settings: { theme: 'dark', lang: 'en' },
        data: { value: 100 }
      }
      const result = Pick.pick(object, 'user', 'settings')
      const expected = {
        user: { name: 'John', age: 30 },
        settings: { theme: 'dark', lang: 'en' }
      }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "11. 对象选择高级方法 - 嵌套属性选择测试:",
    (() => {
      const object = {
        user: { profile: { name: 'John', age: 30 } },
        settings: { theme: 'dark' }
      }
      const result = Pick.pickDeep(object, 'user.profile.name')
      const expected = {
        user: { profile: { name: 'John' } }
      }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "12. 对象选择高级方法 - 混合类型选择测试:",
    (() => {
      const object = { a: 1, b: '2', c: true, d: null, e: undefined }
      const result = Pick.pickByType(object, 'number')
      const expected = { a: 1 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "13. 对象选择高级方法 - 正则模式选择测试:",
    (() => {
      const object = { user_name: 'John', user_age: 30, data_value: 100 }
      const result = Pick.pickByPattern(object, /^user_/)
      const expected = { user_name: 'John', user_age: 30 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "14. 对象选择高级方法 - 条件组合选择测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Pick.pickBy(object, (value, key) => value > 2 && key !== 'd')
      const expected = { c: 3, e: 5 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )

  console.log(
    "15. 对象选择高级方法 - 转换组合选择测试:",
    (() => {
      const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
      const result = Pick.pickWithTransform(object, 'a', 'b', {
        a: x => x * 2,
        b: x => x * 3
      })
      const expected = { a: 2, b: 6 }
      return JSON.stringify(result) === JSON.stringify(expected)
    })()
  )
}

testPickAdvancedMethods()
